package de.gameduell.framework.gui.animation {
	import fl.transitions.TweenEvent;	

	/**
	 * @author cbra
	 */
	public class TweenManager {
		private static var instance:TweenManager;	
		private var _tweens:Array;

		public static function getInstance():TweenManager {
			if(instance == null) {
				instance = new TweenManager();
			}
			return instance;
		}

		public function TweenManager() {
			_tweens = new Array();
		}
		
		public function get tweens():Array{
			return _tweens;
		}

		public function add(tweenable:Tweenable):void {
			_tweens.push(tweenable);
			tweenable.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinished);
		}

		private function onMotionFinished(event:TweenEvent):void {
			var tempTweens:Array = _tweens.slice();
			for(var i:* in tempTweens){
				if(event.target == _tweens[i]){
					_tweens.splice(i,1);
				}
			}
		}
	}
}
